import request from '../../../components/Request';

export async function listCategory() {
  let result = await request.post({
    url: './common/listCategory.do',
    data: { type: 1 },
  });
  return result.data;
}


export async function listDict(pageNo, pageSize, categoryId, name) {
  let result = await request.post({
    url: './dict/listDict.do',
    data: { pageNo: pageNo, pageSize: pageSize, categoryId: categoryId, name: name },
  });
  return result.data;
}

export async function saveDict(dict) {
  let result = await request.post({
    url: './dict/saveDict.do',
    data: dict,
  });
  return result;
}

export async function deleteDict(id) {
  await request.post({
    url: './dict/deleteDict.do',
    data: { id: id },
  });
}

export async function saveDictItem(dict, dictItemList) {
   let reqData = dictItemList.map(function(dictItem) {
     dictItem.dictId = dict.id;
     return dictItem;
   })
  await request.post({
    url: './dict/saveDictItem.do',
    contentType: request.CONTENT_TYPE_JSON,
    data: reqData,
  });
}

export async function listDictItem(dictId) {
  let result = await request.post({
    url: './dict/listDictItem.do',
    data: { dictId: dictId },
  });

  return result.data;
}
